﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;

namespace apiApplication1.Controllers
{

    public class Product
    {
        public int id { get; set; }
        public string name { get; set; }
        [Required]
        public decimal price { get; set; }
        [Required]
        public int CategoryId { get; set; }
    }

    public class Category
    {
        public int id { get; set; }
        public string name { get; set; }
        public IEnumerable<Product> products { get; set; }
    }
    //[EntityFrameworks.Web.Core.Attributes.BasicAuthentication]
    public class ProductsController : ApiController
    {
        //
        // GET: /Products/

        public IEnumerable<Category> Get()
        {
            List<Category> categorys = new List<Category>();
            categorys.Add(new Category
            {
                id = 1,
                name = "数码",
                products = new List<Product>
                {
                 new Product{id=1,name="电脑",price=4999,CategoryId=1},
                 new Product{id=2,name="手机",price=2999,CategoryId=1}
                }
            });

            categorys.Add(new Category
            {
                id = 2,
                name = "生活用品",
                products = new List<Product>
                {
                 new Product{id=3,name="自行车",price=999,CategoryId=2},
                 new Product{id=4,name="摩托车",price=1999,CategoryId=2}
                }
            });
            return categorys;
        }


    }
}
